package com.atguigu.eduorder.service.impl;

import com.atguigu.commonutils.orderVo.CourseVo;
import com.atguigu.commonutils.orderVo.UcenterVo;
import com.atguigu.eduorder.client.CourseClient;
import com.atguigu.eduorder.client.UcenterClient;
import com.atguigu.eduorder.entity.TOrder;
import com.atguigu.eduorder.mapper.TOrderMapper;
import com.atguigu.eduorder.service.TOrderService;
import com.atguigu.eduorder.utils.OrderNoUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.ParameterResolutionDelegate;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-04-17
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {

    @Autowired
    private CourseClient courseClient;

    @Autowired
    private UcenterClient ucenterClient;

    //生成订单
    @Override
    public String createOrder(String courseId, String memberId) {
        //远程调用获取到用户和课程的信息
        CourseVo courseVo = courseClient.getCourseInfoOrder(courseId);
        UcenterVo ucenterVo = ucenterClient.getUserInfoOrder(memberId);
        //创建order对象
        TOrder order = new TOrder();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseVo.getTitle());
        order.setCourseCover(courseVo.getCover());
        order.setTeacherName(courseVo.getTeacherName());
        order.setTotalFee(courseVo.getPrice());
        order.setMemberId(memberId);
        order.setMobile(ucenterVo.getMobile());
        order.setNickname(ucenterVo.getNickname());
        order.setStatus(0);     //支付状态 已支付 未支付
        order.setPayType(1);       //支付类型 1代表微信 2代表支付宝
        //添加到数据库
        baseMapper.insert(order);

        return order.getOrderNo();
    }
}
